<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('停车费')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>项目名称：</label>
                            <input type="text" name="projectName"/>
                        </li>
                        <li>
                            <label>单位名称：</label>
                            <input type="text" name="unitName"/>
                        </li>
                        <li>
                            <label>车牌号：</label>
                            <input type="text" name="licensePlateNum" />
                        </li>
                        <li>
                            <label>起始日期：</label>
                            <div class="input-daterange input-group"><!--time-input-->
                                <input type="text" class="time-input" name="createBeginTime" placeholder="请填写日期"/>
                                <span>&nbsp;到&nbsp;</span>
                                <input type="text" class="time-input" name="createOverTime" placeholder="请填写日期"/>
                            </div>
                        </li>
                        <li>
                            <label>结束日期：</label>
                            <div class="input-daterange input-group">
                                <input type="text" class="time-input" name="updateBeginTime" placeholder="请填写日期"/>
                                <span>&nbsp;到&nbsp;</span>
                                <input type="text" class="time-input" name="updateOverTime" placeholder="请填写日期"/>
                            </div>
                        </li>
                        <li>
                            <label>状态：</label>
                            <select name="status" class="">
                                <option value="">所有</option>
                                <option value="0">正常</option>
                                <option value="1">到期</option>
                                <option value="2">退租</option>
                            </select>
                        </li>
                        <li>
                            <label>到账状态：</label>
                            <select name="accountStatus" class="">
                                <option value="">所有</option>
                                <option value="0">已到账</option>
                                <option value="1">未到账</option>
                            </select>
                        </li>
                        <li>
                            <label>开票时间：</label>
                            <div class="input-daterange input-group">
                                <input type="text" class="time-input" name="billingBeginTime" placeholder="请填写日期"/>
                                <span>&nbsp;到&nbsp;</span>
                                <input type="text" class="time-input" name="billingOverTime" placeholder="请填写日期"/>
                            </div>
                        </li>
                        <li>
                            <label>到账时间：</label>
                            <div class="input-daterange input-group">
                                <input type="text" class="time-input" name="paymentBeginDate" placeholder="请填写日期"/>
                                <span>&nbsp;到&nbsp;</span>
                                <input type="text" class="time-input" name="paymentOverDate" placeholder="请填写日期"/>
                            </div>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="query()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="guomao:parkRate:add">
                <i class="fa fa-plus"></i> 增加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="guomao:parkRate:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="guomao:parkRate:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-success" onclick="$.table.importExcel()" shiro:hasPermission="guomao:parkRate:import">
                <i class="fa fa-upload"></i> 导入
            </a>
            <a class="btn btn-warning" onclick="exportExcel()" shiro:hasPermission="guomao:parkRate:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-success single disabled" onclick="openUpload()" shiro:hasPermission="guomao:parkRate:upload">
                <i class="fa fa-upload"></i> 上传附件
            </a>
            <a class="btn btn-warning single disabled" onclick="downInfo()" shiro:hasPermission="guomao:parkRate:download">
                <i class="fa fa-download"></i> 下载附件
            </a>

        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('guomao:parkRate:edit')}]];
    var removeFlag = [[${@permission.hasPermi('guomao:parkRate:remove')}]];
    var prefix = ctx + "guomao/parkRate";
    var options;
        function query() {
            if (options != null && options != undefined) {
                var params = $("#bootstrap-table").bootstrapTable('getOptions');
                $("#bootstrap-table").bootstrapTable('refresh', params);
            } else {
                options = {
                    url: prefix + "/list",
                    createUrl: prefix + "/add",
                    updateUrl: prefix + "/edit/{id}",
                    removeUrl: prefix + "/remove",
                    exportUrl: prefix + "/export",
                    importUrl: prefix + "/importExcel",
                    importTemplateUrl: prefix + "/importTemplate",
                    uniqueId: "parkId",
                    modalName: "停车费",
                    columns: [{
                        checkbox: true
                    }, {
                        field: 'parkId',
                        title: '停车费编号',
                        visible: false
                    }, {
                        field: 'num',
                        title: '序号',
                    },
                        {
                            field: 'projectName',
                            title: '项目名称'
                        },
                        {
                            field: 'unitName',
                            title: '单位名称'
                        },
                        {
                            field: 'licensePlateNum',
                            title: '车牌号'
                        },
                        {
                            field: 'unitPrice',
                            title: '单价'
                        },
                        {
                            field: 'createTime',
                            title: '起始日期'
                        },
                        {
                            field: 'updateTime',
                            title: '结束日期',
                        },
                        {
                            field: 'status',
                            title: '状态',
                            formatter: function (value, row, index) {
                                if (row.status == "0") {
                                    return '<span class="label label-primary">正常</span>';
                                } else if (row.status == "1") {
                                    return '<span class="label label-success">到期</span>';
                                } else if (row.status == "2") {
                                    return '<span class="label label-warning">退租</span>';
                                } else {
                                    return '<span class="label label-danger">异常</span>';
                                }
                            }
                        },
                        {
                            field: 'billingTime',
                            title: '开票时间',
                        },
                        {
                            field: 'invoicedAmount',
                            title: '开票金额'
                        },
                        {
                            field: 'paymentDate',
                            title: '到账时间'
                        },
                        {
                            field: 'amountReceived',
                            title: '到账金额'
                        },
                        {
                            field: 'accountStatus',
                            title: '到账状态',
                            formatter: function (value, row, index) {
                                if (row.accountStatus == "0") {
                                    return '<span class="label label-primary">已到账</span>';
                                } else if (row.accountStatus == "1") {
                                    return '<span class="label label-success">未到账</span>';
                                } else {
                                    return '<span class="label label-danger">异常</span>';
                                }
                            }
                        },
                        {
                            field: 'fileCount',
                            title: '附件数'
                        },
                        {
                            field: 'remark',
                            title: '备注'
                        },
                        {
                            title: '操作',
                            align: 'center',
                            formatter: function (value, row, index) {
                                var actions = [];
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.parkId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.parkId + '\')"><i class="fa fa-remove"></i>删除</a>');
                                return actions.join('');
                            }
                        }
                    ]
                };
                $.table.init(options);
            }
        }

    // $(function (){
    //     var date = new Date();
    //     var year = date.getFullYear();
    //     var month = date.getMonth() + 1;
    //     if(month == 0){
    //         month = 12;
    //         year = year - 1;
    //     }
    //     if(month < 10){
    //         month = "0" + month;
    //     }
    //     $('#etldt').val(""+year+month);
    // });

    /*导出接口*/
    // function exportExcel(){
    //     var rows=$.table.selectColumns(table.options.uniqueId);
    //     $.modal.confirm("确认要导出所选数据吗?", function() {
    //         var url = table.options.exportUrl;
    //         var data = { "ids": rows.join() };
    //         $.modal.loading("正在导出数据，请稍后...");
    //         $.post(url,data,function (res) {
    //             if (res.code == web_status.SUCCESS) {
    //                 window.location.href = ctx + "common/download?fileName=" + encodeURI(res.msg) + "&delete=" + true;
    //             } else if (res.code == web_status.WARNING) {
    //                 $.modal.alertWarning(res.msg)
    //             } else {
    //                 $.modal.alertError(res.msg);
    //             }
    //             $.modal.closeLoading();
    //         })
    //     });
    // }
    function exportExcel(){
        var rows=$.table.selectColumns(table.options.uniqueId);
        var msg = "确定导出" + table.options.modalName + "吗？"
        if(rows.length!=0){
            msg = "确定导出勾选的"+rows.length+"条数据吗？"
        }
        $.modal.confirm(msg, function() {
            var params = $("#" + table.options.id).bootstrapTable('getOptions');
            var dataParam = $("#formId").serializeArray();
            dataParam.push({ "name": "orderByColumn", "value": params.sortName });
            dataParam.push({ "name": "isAsc", "value": params.sortOrder });
            if(rows.length!=0){
                dataParam.push({"name": "ids", "value": rows.join()});
            }
            $.modal.loading("正在导出数据，请稍后...");
            $.post(table.options.exportUrl, dataParam, function(result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        });
    }

    /**
     * 附件上传
     * */
    function openUpload(){
        var rows = $.table.selectColumns("parkId");
        if (rows.length!=1){
            $.modal.alertWarning("请选择一条数据进行上传！");
            return;
        }
        var parkId = rows.join();
        $.modal.openTab("上传附件", prefix + "/toUpload/"+parkId);
    }

    function downInfo(){
        var rows = $.table.selectColumns("parkId");
        if (rows.length!=1){
            $.modal.alertWarning("请选择一条数据进行下载！");
            return;
        }
        var parkId = rows.join();
        $.modal.loading("正在下载请稍后...");
        $.post(prefix+"/downloadInfo",{"parkId":parkId},function (res) {
            if (res.code == web_status.SUCCESS) {
                window.location.href = prefix + "/downloadInfo?fileName=" + encodeURI(res.data);
            } else if (res.code == web_status.WARNING) {
                $.modal.alertWarning(res.msg);
            } else {
                $.modal.alertError(res.msg);
            }
            $.modal.closeLoading();
        })
    }



</script>
</body>

<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果参数已经存在，更新这条数据。"> 是否更新已经存在的参数数据
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs" shiro:hasPermission="guomao:parkRate:template"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！！！
            </font>
        </div>
    </form>
</script>

</html>